package asn.match.service;

import java.sql.Timestamp;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import asn.match.dao.MemberAccountDaoImpl;
import asn.match.model.MemberAccount;

@Service("memberAccountService")
@Transactional(propagation=Propagation.SUPPORTS, readOnly=true)
public class MemberAccountServiceImpl implements MemberAccountService {

	@Autowired
	MemberAccountDaoImpl memberAccountDaoImpl;
	
	@Override
	public void addMemberAccount(MemberAccount memberAccount) {
		Date date = new Date();
		Timestamp created_at = new Timestamp(date.getTime());

		memberAccount.setConnectionStatus("offline");
		memberAccount.setCreatedAt(created_at);
		memberAccount.setModifiedAt(created_at);
		memberAccount.setStatus("registration_process");
		this.memberAccountDaoImpl.addMemberAccount(memberAccount);

	}

	@Override
	public void updateMemberAccount(MemberAccount memberAccount) {
		this.memberAccountDaoImpl.updateMemberAccount(memberAccount);
	}

	@Override
	public void deleteMemberAccount(MemberAccount memberAccount) {
		this.memberAccountDaoImpl.deleteMemberAccount(memberAccount);
	}

	@Override
	public List<MemberAccount> findAllMemberAccounts() {
		return this.memberAccountDaoImpl.findAllMemberAccounts();
	}

	@Override
	public MemberAccount findMemberAccountById(Integer memberAccountId) {
		return this.memberAccountDaoImpl.findMemberAccountById(memberAccountId);
	}

	@Override
	public List<MemberAccount> findMemberAccountByLinkname(String linkname) {
		return this.memberAccountDaoImpl.findMemberAccountByLinkname(linkname);
	}

	@Override
	public boolean checkValidationCodeExists(String validationCode) {
		List<MemberAccount> listElement = this.memberAccountDaoImpl.findMemberAccountByValidationCode(validationCode);
		if(listElement.size()>0){
			return true;
		}
		return false;
	}

	@Override
	public boolean checkEmailExists(String email) {
		List<MemberAccount> listElement = this.memberAccountDaoImpl.findMemberAccountByEmail(email);
		if(listElement.size()>0){
			return true;
		}
		return false;
	}

	@Override
	public boolean checkLinknameExists(String linkname) {
		List<MemberAccount> listElement = this.memberAccountDaoImpl.findMemberAccountByLinkname(linkname);
		if(listElement.size()>0){
			return true;
		}
		return false;
	}

	@Override
	public List<MemberAccount> findMemberAccountByValidationCode(
			String validationCode) {
		return this.memberAccountDaoImpl.findMemberAccountByValidationCode(validationCode);
	}

	@Override
	public List<MemberAccount> findMemberAccountByEmail(String email) {
		return this.memberAccountDaoImpl.findMemberAccountByEmail(email);
	}

}
